package zjhr.com.service.impl;

import java.util.List;

import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import zjhr.com.mapper.ExpenseZjMapper;
import zjhr.com.pojo.EasyUIPageQuery;
import zjhr.com.pojo.ExpenseZj;
import zjhr.com.service.ExpenseService;
import zjhr.com.utils.IDUtils;
@Service
public class ExpenseServiceImpl implements ExpenseService {
	@Autowired
	private ExpenseZjMapper expenseMapper;

	@Override
	public void save(ExpenseZj expense) {
		expense.setBxid(IDUtils.genImageName());
		expenseMapper.insert(expense);
	}

	@Override
	public EasyUIPageQuery pageQuery(Integer page, Integer rows) {
		int total = expenseMapper.countByExample(null);
		int start = (page-1)*rows;
		List<ExpenseZj> list = expenseMapper.pageQuery(start, rows);
		EasyUIPageQuery pageQuery = new EasyUIPageQuery(total, list);
		return pageQuery;
	}
	//修改
	@Override
	public void edit(ExpenseZj expense) {
		expenseMapper.updateByPrimaryKey(expense);
	}
	//审批
	@Override
	public void updateType(String ids) {
		if(StringUtils.isNotBlank(ids)){
			String[] idstr = ids.split(",");
			for (String bxid : idstr) {
				 expenseMapper.updateType(bxid);
			}
		}
	}
	//审批
	@Override
	public void checkType(ExpenseZj expense) {
		expenseMapper.checkType(expense);
	}
	//业务部分页
	@Override
	public EasyUIPageQuery pageQueryByBusiness(Integer page, Integer rows, String bxJob) {
		int total = expenseMapper.countByExample(null);
		int start = (page-1)*rows;
		List<ExpenseZj> list = expenseMapper.pageQueryByBusiness(bxJob,start, rows);
		EasyUIPageQuery pageQuery = new EasyUIPageQuery(total, list);
		return pageQuery;
	}
	//根据审批日期导出
	@Override
	public List<ExpenseZj> export(String beginDate, String endDate) {
		List<ExpenseZj> expense = expenseMapper.exportExpense(beginDate, endDate);
		return expense;
	}

}
